<template>
 <div class="icons">
 <swiper :options="swiperOption">
 <swiper-slide v-for="(page , index) of pages" :key="index">
  <div class="icon" v-for="icon of page" :key="icon.id">
  <div class="icon_img">
  <img :src="icon.img" class="icon_content">
  <p class="icon_text">{{icon.text}}</p>
  </div>
  </div>
  </swiper-slide>
  </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: ['icons'],
  data () {
    return {
      swiperOption: {
        autoplayDisableOnInteraction: false, // 触摸后再次自动轮播
        autoplay: false // 禁止自动换页
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.icons.forEach((item, index) => {
        // 判断展示在下标为0还是1的页面上，floor向下取整，<8,则都在第一页
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        // 二维数组，[page][item]
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/style/varibles.styl'
.icons>>> .swiper-container
  height :0
  padding-bottom :50%
.icons
  margin-top : -1.5rem
  .icon
    position :relative
    overflow :hidden
    float : left
    width : 25%
    padding-bottom : 25%
    .icon_img
     position : absolute;
     top : 0
     right :0
     left :0
     bottom :0
     box-sizing : border-box
     padding : 1.5rem
    .icon_text
     text-align :center
     color : $darkTextColor
    .icon_content
       height : 100%
       width  : 100%
</style>
